<?php

class User {
	
	/**
	 * @var integer
	 */
	private $id;
	private $expireDate;
	
	/**
	 * @var string
	 */
	private $username;
	private $passwordEncrypted;
	private $tempPassword;
	private $picture;
	
	/**
	 * @param integer	 $id
	 * @param string 	$username
	 * @param string 	$password
	 * @param string 	$picture
	 * @param integer 	$expireDate
	 */
	public function __construct($id, $username, $password, $picture, $expireDate) {
		$this->id = $id;
		$this->username = $username;
		$this->passwordEncrypted = $password;
		$this->picture = $picture;
		$this->expireDate = $expireDate;
	}
	
	/**
	 * @param User $other
	 * 
	 * @return boolean
	 */
	public function isSame(User $other) {
		if ($this->username == $other->username) {
			return true;
		}
		return false;
	}
	
	/**
	 * @param string $passwordEncrypted
	 * 
	 * @return boolean
	 */
	public function matchPasswords($passwordEncrypted) {
		if (strcmp($this->passwordEncrypted, $passwordEncrypted) != 0) {
			return false;
		}
		return true;
	}
	
	/**
	 * @param int $expireDate
	 * 
	 * @return boolean
	 */
	public function checkExpireDate($expireDate) {
		if (time() > $expireDate) {
			return false;
		}
		return true;
	}

	public function createTempPassword() {
		$this->tempPassword = $this->passwordEncrypted . "<>" . $this->expireDate;
	}
		
	public function createNewTempPassword() {
		$this->expireDate = time() + 20;
		$this->createTempPassword();
	}
	
	/**
	 * @return integer
	 */
	public function getId() {
		return $this->id + 0;
	}
	
	/**
	 * @return string
	 */
	public function getUsername() {
		return $this->username;
	}
	
	/**
	 * @return string
	 */
	public function getPasswordEncrypted() {
		return $this->passwordEncrypted;
	}
	
	/**
	 * @return string
	 */
	public function getPicture() {
		return $this->picture;
	}
	
	/**
	 * @return integer
	 */
	public function getExpireDate() {
		return $this->expireDate + 0;
	}
	
	/**
	 * @return string
	 */
	public function getTempPassword() {
		return $this->tempPassword;
	}
	
	/**
	 * @return string
	 */
	public function getPostList() {
		return $this->postList;
	}
}